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

📄 servhs.cpp

📁 这是和p2p相关的一份源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
					{						if (hasCGIarg(cmd,"stop"))							s->thread.active = false;					}					s=s->next;				}				sprintf(jumpStr,"/admin?page=connections");									jumpArg = jumpStr;			}else if (cmpCGIarg(cmd,"cmd=","shutdown"))			{				servMgr->shutdownTimer = 1;			}else if (cmpCGIarg(cmd,"cmd=","stop"))			{				GnuID id;				char *cp = cmd;				while (cp=nextCGIarg(cp,curr,arg))				{					if (strcmp(curr,"id")==0)						id.fromStr(arg);				}				Channel *c = chanMgr->findChannelByID(id);				if (c)					c->thread.active = false;				sys->sleep(500);				sprintf(jumpStr,"/admin?page=mychans");									jumpArg = jumpStr;			}else if (cmpCGIarg(cmd,"cmd=","bump"))			{				GnuID id;				char *cp = cmd;				while (cp=nextCGIarg(cp,curr,arg))				{					if (strcmp(curr,"id")==0)						id.fromStr(arg);				}				Channel *c = chanMgr->findChannelByID(id);				if (c)					c->bump = true;				sprintf(jumpStr,"/admin?page=mychans");									jumpArg = jumpStr;			}else if (cmpCGIarg(cmd,"cmd=","keep"))			{				GnuID id;				char *cp = cmd;				while (cp=nextCGIarg(cp,curr,arg))				{					if (strcmp(curr,"id")==0)						id.fromStr(arg);				}				Channel *c = chanMgr->findChannelByID(id);				if (c)					c->stayConnected = true;				sprintf(jumpStr,"/admin?page=mychans");									jumpArg = jumpStr;			}else if (cmpCGIarg(cmd,"cmd=","relay"))			{
				ChanInfo info;				char *cp = cmd;				while (cp=nextCGIarg(cp,curr,arg))				{					if (strcmp(curr,"id")==0)						info.id.fromStr(arg);				}				if (!chanMgr->findChannelByID(info.id))				{					ChanHitList *chl = chanMgr->findHitList(info);					if (!chl)						throw StreamException("channel not found");					Channel *c = chanMgr->createChannel(chl->info,NULL);					if (!c)						throw StreamException("out of channels");					c->stayConnected = true;					c->startGet();				}				sprintf(jumpStr,"/admin?page=mychans");									jumpArg = jumpStr;			}else if (cmpCGIarg(cmd,"page=","chans"))			{				ChanInfo info;				info.init();				SORT sort=SORT_NAME;				bool dir=false;				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);					else if (strcmp(curr,"sort")==0)					{						if (strcmp(arg,"name")==0)							sort = SORT_NAME;						else if (strcmp(arg,"bitrate")==0)							sort = SORT_BITRATE;						else if (strcmp(arg,"listeners")==0)							sort = SORT_LISTENERS;						else if (strcmp(arg,"hosts")==0)							sort = SORT_HOSTS;						else if (strcmp(arg,"type")==0)							sort = SORT_TYPE;						else if (strcmp(arg,"genre")==0)							sort = SORT_GENRE;					}else if (strcmp(curr,"dir")==0)					{						if (strcmp(arg,"up")==0)							dir = true;						else if (strcmp(arg,"down")==0)							dir = false;					}				}				addAllChannelsPage(html,sort,dir,&info);			}else if (cmpCGIarg(cmd,"page=","winamp-settings"))			{				addWinampSettingsPage(html);			}else if (cmpCGIarg(cmd,"page=","winamp-chans"))			{				char wildcard[128],type[128];				bool stop=false;				wildcard[0] = type[0]=0;				char *cp = cmd;				while (cp=nextCGIarg(cp,curr,arg))				{					if (strcmp(curr,"wildcard")==0)						strcpy(wildcard,arg);					else if (strcmp(curr,"type")==0)						strcpy(type,arg);					else if (strcmp(curr,"stop")==0)						stop=true;				}				addWinampChansPage(html,wildcard,type,stop);			}else if (cmpCGIarg(cmd,"page=","mychans"))			{				addMyChannelsPage(html);			}else if (cmpCGIarg(cmd,"html=","index"))			{				html.writeTemplate("html/index.html");			}else if (cmpCGIarg(cmd,"page=","index"))			{				addAdminPage(html);			}else if (cmpCGIarg(cmd,"page=","settings"))			{				addSettingsPage(html);			}else if (cmpCGIarg(cmd,"page=","viewlog"))			{				addLogPage(html);			}else if (cmpCGIarg(cmd,"page=","viewnet"))			{				addNetStatsPage(html);			}else if (cmpCGIarg(cmd,"page=","shutdown"))			{				addShutdownPage(html);			}else if (cmpCGIarg(cmd,"page=","logout"))			{				addLogoutPage(html);			}else if (cmpCGIarg(cmd,"page=","connections"))			{				addConnectionsPage(html);			}else if (cmpCGIarg(cmd,"page=","broadcast"))			{				addBroadcastPage(html);			}else if (cmpCGIarg(cmd,"net=","add"))			{								GnuID id;				id.clear();				while (cmd=nextCGIarg(cmd,curr,arg))				{					if (strcmp(curr,"ip")==0)					{						Host h;						h.fromStrIP(arg,DEFAULT_PORT);						if (servMgr->addOutgoing(h,id,true))							LOG_NETWORK("Added connection: %s",arg);					}else if (strcmp(curr,"id")==0)					{						id.fromStr(arg);					}				}			}else if (cmpCGIarg(cmd,"cmd=","logout"))			{				jumpArg = "/";				servMgr->cookieList.remove(cookie);			}else if (cmpCGIarg(cmd,"cmd=","login"))			{				GnuID id;				char idstr[64];				id.generate();				id.toStr(idstr);				cookie.set(idstr,sock->host.ip);				servMgr->cookieList.add(cookie);					http.writeLine(HTTP_SC_FOUND);				if (servMgr->cookieList.neverExpire)					http.writeLine("%s id=%s; path=/; expires=\"Mon, 01-Jan-3000 00:00:00 GMT\";",HTTP_HS_SETCOOKIE,idstr);				else					http.writeLine("%s id=%s; path=/;",HTTP_HS_SETCOOKIE,idstr);				http.writeLine("Location: /");				http.writeLine("");			}else{				addAdminPage(html);			}		}	}catch(StreamException &e)	{		html.startTagEnd("h1","ERROR - %s",e.msg);		LOG_ERROR("html: %s",e.msg);	}	if (retHTML)	{		if (jumpArg)		{			String jmp(jumpArg,String::T_HTML);			jmp.convertTo(String::T_ASCII);			html.locateTo(jmp.cstr());		}	}}// -----------------------------------static XML::Node *createChannelXML(Channel *c){	XML::Node *n = c->info.createChannelXML();	n->add(c->createRelayXML(true));	n->add(c->info.createTrackXML());//	n->add(c->info.createServentXML());	return n;}// -----------------------------------static XML::Node *createChannelXML(ChanHitList *chl){	XML::Node *n = chl->info.createChannelXML();	n->add(chl->createHitsXML());	n->add(chl->info.createTrackXML());//	n->add(chl->info.createServentXML());	return n;}// -----------------------------------void Servent::handshakeXML(){	int i;				    sock->writeLine(HTTP_SC_OK);	sock->writeLine("%s %s",HTTP_HS_SERVER,PCX_AGENT);    sock->writeLine("%s %s",HTTP_HS_CONTENT,MIME_XML);	sock->writeLine("Connection: close");    sock->writeLine("");	XML xml;	XML::Node *rn = new XML::Node("peercast");	xml.setRoot(rn);	rn->add(new XML::Node("servent uptime=\"%d\"",servMgr->getUptime()));	rn->add(new XML::Node("bandwidth out=\"%d\" in=\"%d\"",servMgr->totalOutput(false),chanMgr->totalInput()));	rn->add(new XML::Node("connections total=\"%d\" streams=\"%d\"",servMgr->totalConnected(),servMgr->numStreams(false)));	Channel *clist[ChanMgr::MAX_CHANNELS];	ChanInfo info;	int num = chanMgr->findChannels(info,clist,ChanMgr::MAX_CHANNELS);	XML::Node *an = new XML::Node("channels_relayed total=\"%d\"",num);	rn->add(an);	for(i=0; i<num; i++)		an->add(createChannelXML(clist[i]));	XML::Node *fn = new XML::Node("channels_found total=\"%d\"",chanMgr->numHitLists());	rn->add(fn);	for(i=0; i<ChanMgr::MAX_HITLISTS; i++)		if (chanMgr->hitlists[i].isUsed())			fn->add(createChannelXML(&chanMgr->hitlists[i]));	XML::Node *hc = new XML::Node("host_cache");	for(i=0; i<ServMgr::MAX_HOSTCACHE; i++)	{		ServHost *sh = &servMgr->hostCache[i];		if (sh->type != ServHost::T_NONE)		{			char ipstr[64];			sh->host.toStr(ipstr);			hc->add(new XML::Node("host ip=\"%s\" type=\"%s\" time=\"%d\"",ipstr,ServHost::getTypeStr(sh->type),sh->time));		}	}
	rn->add(hc);


	XML::Node *tc = new XML::Node("trackers");
	for(i=0; i<ChanHitList::MAX_HITS; i++)
		if (chanMgr->trackerHitList.hits[i].host.ip)
			tc->add(chanMgr->trackerHitList.hits[i].createXML());
	rn->add(tc);
	xml.write(*sock);

}// -----------------------------------void Servent::handshakeHTML(char *cmd){	HTTP http(*sock);	char tmp[512];	while (http.nextHeader())		LOG_DEBUG("HTTP: %s",http.cmdLine);	char name[128];	//servMgr->serverHost.toResolvedName(name);	servMgr->serverHost.toStr(name);	sprintf(tmp,"PeerCast on %s",name);	HTML html(tmp,*sock);	bool showLogin=true;	if (!strlen(servMgr->password) && sock->host.isLocalhost())		showLogin = false;		sock->writeLine(HTTP_SC_FOUND);		//sock->writeLine("Location: /admin?page=index");		sock->writeLine("Location: /admin?");		sock->writeLine("");		return;	if (showLogin)	{		addLoginPage(html);	}else{		sock->writeLine(HTTP_SC_FOUND);		//sock->writeLine("Location: /admin?page=index");		sock->writeLine("Location: /admin?");		sock->writeLine("");	}}// -----------------------------------void Servent::readICYHeader(HTTP &http, ChanInfo &info, char *pwd, bool isTrusted){	char *arg = http.getArgStr();	if (!arg) return;	if (http.isHeader("x-audiocast-name") || http.isHeader("icy-name") || http.isHeader("ice-name"))		info.name.set(arg,String::T_ASCII);	else if (http.isHeader("x-audiocast-url") || http.isHeader("icy-url") || http.isHeader("ice-url"))		info.url.set(arg,String::T_ASCII);	else if (http.isHeader("x-audiocast-bitrate") || http.isHeader("ice-bitrate"))		info.bitrate = atoi(arg);	else if (http.isHeader("x-audiocast-genre") || http.isHeader("ice-genre"))		info.genre.set(arg,String::T_ASCII);	else if (http.isHeader("x-audiocast-description") || http.isHeader("ice-description"))		info.desc.set(arg,String::T_ASCII);	else if ((http.isHeader("icy-br")) || http.isHeader("ice-bitrate"))		info.bitrate = atoi(arg);	else if (http.isHeader("icy-genre"))		info.genre.set(arg,String::T_ASCII);	else if (http.isHeader("Authorization"))		http.getAuthUserPass(NULL,pwd);	else if (http.isHeader(PCX_HS_CHANNELID))		info.id.fromStr(arg);
	else if (http.isHeader("ice-password"))	{		if (pwd)			if (strlen(arg) < 64)				strcpy(pwd,arg);	}else if (http.isHeader("content-type"))	{		if (stristr(arg,MIME_OGG))			info.contentType = ChanInfo::T_OGG;		else if (stristr(arg,MIME_XOGG))			info.contentType = ChanInfo::T_OGG;		else if (stristr(arg,MIME_MP3))			info.contentType = ChanInfo::T_MP3;		else if (stristr(arg,MIME_XMP3))			info.contentType = ChanInfo::T_MP3;		else if (stristr(arg,MIME_WMA))			info.contentType = ChanInfo::T_WMA;		else if (stristr(arg,MIME_WMV))			info.contentType = ChanInfo::T_WMV;		else if (stristr(arg,MIME_ASX))			info.contentType = ChanInfo::T_ASX;		else if (stristr(arg,MIME_NSV))			info.contentType = ChanInfo::T_NSV;		else if (stristr(arg,MIME_RAW))			info.contentType = ChanInfo::T_RAW;
		else if (stristr(arg,MIME_MMS))			info.srcProtocol = ChanInfo::SP_MMS;
		else if (stristr(arg,MIME_XPCP))
			info.srcProtocol = ChanInfo::SP_PCP;
		else if (stristr(arg,MIME_XPEERCAST))
			info.srcProtocol = ChanInfo::SP_PEERCAST;
		else if (stristr(arg,MIME_XSCPLS))			info.contentType = ChanInfo::T_PLS;		else if (stristr(arg,MIME_PLS))			info.contentType = ChanInfo::T_PLS;		else if (stristr(arg,MIME_XPLS))			info.contentType = ChanInfo::T_PLS;		else if (stristr(arg,MIME_M3U))			info.contentType = ChanInfo::T_PLS;		else if (stristr(arg,MIME_TEXT))			info.contentType = ChanInfo::T_PLS;	}}// -----------------------------------void Servent::handshakeICY(Channel::SRC_TYPE type, bool isHTTP){	ChanInfo info;	HTTP http(*sock);	// default to mp3 for shoutcast DSP (doesn`t send content-type)	if (type == Channel::SRC_SHOUTCAST)		info.contentType = ChanInfo::T_MP3;	while (http.nextHeader())	{		LOG_DEBUG("ICY %s",http.cmdLine);		readICYHeader(http,info,loginPassword,false);	}			// check password before anything else, if needed	if (strcmp(servMgr->password,loginPassword)!=0)		throw HTTPException(HTTP_SC_UNAUTHORIZED,401);
		
	// we need a valid IP address before we start
	servMgr->checkFirewall();
	// attach channel ID to name, channel ID is also encoded with IP address 	// to help prevent channel hijacking. 	Host sh = servMgr->serverHost;	info.id = chanMgr->broadcastID;	info.id.encode(&sh,info.name.cstr(),loginMount,info.bitrate);	LOG_DEBUG("Incoming source: %s : %s",info.name.cstr(),ChanInfo::getTypeStr(info.contentType));	if (isHTTP)		sock->writeString("%s\n\n",HTTP_SC_OK);	else		sock->writeLine("OK");
	Channel *c = chanMgr->findChannelByID(info.id);	if (c)
		c->thread.active = false;
	info.comment = chanMgr->broadcastMsg;	c = chanMgr->createChannel(info,loginMount);	if (!c)		throw HTTPException(HTTP_SC_UNAVAILABLE,503);
	c->startICY(sock,type);}

⌨️ 快捷键说明

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